package com.example.dllo.my36kr.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.model.DrawerBean;

import java.util.ArrayList;

/**
 * Created by CPC_272 on 16/8/19.
 */
public class DrawerAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<DrawerBean> data;

    public DrawerAdapter(Context context) {
        this.context = context;
    }

    public void setData(ArrayList<DrawerBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DrawHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_item_drawer, parent, false);
            holder = new DrawHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (DrawHolder) convertView.getTag();
        }
        holder.tv_draw.setText(data.get(position).getTv_draw());
        holder.tag_img.setImageResource(data.get(position).getImg_draw());
        return convertView;
    }

    class DrawHolder {
        private TextView tv_draw;
        private ImageView tag_img;

        public DrawHolder(View view) {
            tv_draw = (TextView) view.findViewById(R.id.tv_drawer);
            tag_img = (ImageView) view.findViewById(R.id.img_drawer);
        }
    }
}
